/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.cje.console.webapi.controller;

import com.chframework.boot.core.response.result.ApiResult;
import com.chframework.common.exception.ApplicationException;
import com.cje.basic.pojo.bo.DictTypeBO;
import com.cje.console.webapi.service.AppConfigService;
import com.cje.console.webapi.service.CommonService;
import com.cje.service.pojo.dto.IpLocationDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
@RequiredArgsConstructor
@RequestMapping("/basic")
public class BasicController {

    private final AppConfigService appConfigService;
    private final CommonService commonService;

    /**
     * 查询指定字典类型的字典数据
     */
    @GetMapping("/getDictList")
    public CompletableFuture<ApiResult<DictTypeBO>> getDictList(String dictType) {
        return appConfigService.getDictList(dictType)
                .exceptionally(throwable -> {
                    throw new ApplicationException(throwable.getCause());
                }).toCompletableFuture();
    }

    /**
     * 获取IP地理定位信息
     */
    @GetMapping("/location")
    public CompletableFuture<ApiResult<IpLocationDTO>> getLocation() {
        return commonService.getLocation()
                .exceptionally(throwable -> {
                    throw new ApplicationException(throwable.getCause());
                }).toCompletableFuture();
    }

}
